var e = require("../../../../../@babel/runtime/helpers/defineProperty");

Component({
    properties: {
        categoryList: {
            type: Array,
            value: []
        }
    },
    data: {
        show: !1,
        sectionOptions: [],
        objectMultiArray: [],
        multiIndex: [ 0, 0, 0 ]
    },
    lifetimes: {
        attached: function() {
            this.data.sectionOptions = this.formatList(this.data.categoryList), this.goodsHandlefunction();
        }
    },
    methods: {
        showPopup: function() {
            this.setData({
                show: !this.data.show
            });
        },
        formatList: function(e) {
            var i = this, n = [];
            return e.forEach(function(e, t) {
                var h = {}, r = e.id, d = e.name;
                h = {
                    id: r,
                    parent_id: e.parent_id,
                    name: d
                }, e.has_many_children && e.has_many_children.length > 0 && (h.children = i.formatList(e.has_many_children)), 
                n[t] = h;
            }), n;
        },
        commodityBtn: function(i) {
            var n = i.detail.column, t = i.detail.value, h = {
                multiArray: this.data.objectMultiArray
            };
            switch (this.setData(e({}, "multiIndex[" + n + "]", t)), n) {
              case 0:
                this.selecommodity_0(t);
                break;

              case 1:
                this.selecommodity_1(this.data.multiIndex[0], t);
            }
            this.setData(h);
        },
        commodityconfirm: function(e) {
            var i = this.data.sectionOptions, n = e.detail.value, t = n[0], h = n[1], r = n[2], d = [], l = [];
            i.length > 0 && (d.push(i[t].id), l.push(i[t].name), i[t].children && i[t].children.length > 0 && (d.push(i[t].children[h].id), 
            l.push(i[t].children[h].name), i[t].children[h].children && i[t].children[h].children.length > 0 && (d.push(i[t].children[h].children[r].id), 
            l.push(i[t].children[h].children[r].name))));
            var a = {};
            d.length >= 1 && (a.parentid = d[0], a.parent_name = l[0]), d.length >= 2 && (a.childid = d[1], 
            a.child_name = l[1]), d.length >= 3 && (a.thirdid = d[2], a.third_name = l[2]), 
            this.triggerEvent("confirmType", {
                manyGoodsCategory: a
            });
        },
        goodsHandlefunction: function() {
            for (var e = this.data.sectionOptions, i = [], n = [], t = [], h = 0; h < e.length; h++) i.push({
                id: e[h].id,
                name: e[h].name
            });
            if (e[0].children && e[0].children.length > 0) for (var r = 0; r < e[0].children.length; r++) n.push({
                id: e[0].children[r].id,
                name: e[0].children[r].name
            });
            if (e[0].children && e[0].children.length > 0 && e[0].children[0].children && e[0].children[0].children.length > 0) for (var d = 0; d < e[0].children[0].children.length; d++) t.push({
                id: e[0].children[0].children[d].id,
                name: e[0].children[0].children[d].name
            });
            this.setData({
                "objectMultiArray[0]": i,
                "objectMultiArray[1]": n,
                "objectMultiArray[2]": t
            });
        },
        selecommodity_0: function(e) {
            var i = this.data.sectionOptions, n = [], t = [];
            if (i[e].children && i[e].children.length > 0) for (var h = 0; h < i[e].children.length; h++) n.push({
                id: i[e].children[h].id,
                name: i[e].children[h].name
            });
            if (i[e].children && i[e].children.length > 0 && i[e].children[0].children && i[e].children[0].children.length > 0) for (var r = 0; r < i[e].children[0].children.length; r++) t.push({
                id: i[e].children[0].children[r].id,
                name: i[e].children[0].children[r].name
            });
            this.setData({
                "objectMultiArray[1]": n,
                "objectMultiArray[2]": t,
                "multiIndex[1]": 0,
                "multiIndex[2]": 0
            });
        },
        selecommodity_1: function(e, i) {
            var n = this.data.sectionOptions, t = [];
            if (n[e].children && n[e].children.length > 0 && n[e].children[i].children && n[e].children[i].children.length > 0) for (var h = 0; h < n[e].children[i].children.length; h++) t.push({
                id: n[e].children[i].children[h].id,
                name: n[e].children[i].children[h].name
            });
            this.setData({
                "objectMultiArray[2]": t,
                "multiIndex[2]": 0
            });
        }
    }
});